package com.atguigu.ssm.service.impl;

import com.atguigu.ssm.mapper.EmployeeMapper;
import com.atguigu.ssm.pojo.Employee;
import com.atguigu.ssm.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService {
    ///@Autowired
    ///private SqlSessionFactory sqlSessionFactory;

    @Autowired
    private EmployeeMapper employeeMapper;

    public PageInfo<Employee> getAllEmployee(Integer pageNum) {
        PageHelper.startPage(pageNum,4);
        List<Employee> list=employeeMapper.getAllEmployee();
        PageInfo<Employee> pageInfo = new PageInfo<Employee>(list, 5);
        return pageInfo;
    }

    public List<Employee> getAllEmployee() {
        return null;
    }

    public PageInfo<Employee> getEmployeePage(Integer pageNum) {
        //开启分页功能
        PageHelper.startPage(pageNum,15);
        List<Employee> list=employeeMapper.getAllEmployee();
        PageInfo<Employee> page = new PageInfo<Employee>(list, 5);
        return page;
    }

    public void save(Employee employee) {
        employeeMapper.insertEmp(employee);
    }

    public void deleteEmployee(Integer empId) {
        employeeMapper.deleteEmp(empId);
    }

    public Employee getEmployeeById(Integer empId) {
        return employeeMapper.getEmployeeById(empId);
    }

    public void updateEmp(Employee employee) {
        employeeMapper.updateEmp(employee);
    }

}
